package st.business.tepth.business.visitor.visitorwork;

import com.alibaba.fastjson.TypeReference;

import io.reactivex.disposables.Disposable;
import st.business.tepth.base.OnDataConvertListener;
import st.business.tepth.business.bean.BusRepairBean;
import st.business.tepth.config.Url;
import st.shadow.library.core.net.callback.IError;
import st.shadow.library.core.net.callback.ISuccess;
import st.shadow.library.core.net.data.ObjConverter;
import st.shadow.library.core.net.rx.RxRestClient;

/**
 * @author zhangyu
 * @date 2019/3/5
 */
public class VisitorWorkModel implements VisitorWorkContract.Model {

    @Override
    public Disposable getBusInfo(int id, final OnDataConvertListener<BusRepairBean> listener) {
        return RxRestClient.builder()
                .url(Url.GetBusRepairStep)
                .params("repairId", id)
                .success(new ISuccess() {
                    @Override
                    public void onSuccess(String response) {
                        listener.convert(convertToBusVisitorRepair(response));
                    }
                })
                .error(new IError() {
                    @Override
                    public void onError(int code, String msg) {
                        listener.error(code, msg);
                    }
                })
                .build()
                .post();
    }
    private BusRepairBean convertToBusVisitorRepair(String response) {
        return new ObjConverter<BusRepairBean>().convert(response
                , new TypeReference<BusRepairBean>() {
                });
    }
}
